import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //这是在服务器的控制台中，打印字符串（服务器是能看到的，客户端是看不到的）
        System.out.println("hello world");
        //这个是给resp的body写入一个字符串作为一个响应返回给浏览器页面，在浏览器上显示
        resp.setContentType("text/html; charset=utf8");
        resp.getWriter().write("这是一个hello world");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("这是一个doPost方法！");
        resp.setContentType("text/html; charset=utf8");
        resp.getWriter().write("这是一个doPost方法！");
    }

    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("这是一个doPut方法！");
        resp.getWriter().write("这是一个doPut方法！");
    }

    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("这是一个doDelete方法！");
        resp.getWriter().write("这是一个doDelete方法！");
    }
}
